package com.facebank.usersupport.controller;

import com.facebank.usersupport.dto.ActivityDto;
import com.facebank.usersupport.dto.AssocitatorDto;
import com.facebank.usersupport.dto.FinanceDto;
import com.facebank.usersupport.model.RestModel;
import com.facebank.usersupport.service.ICountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Auther: yaozun
 * @Date: 2018/3/22 0022 10:17
 * @Description:
 */
@RestController
public class CountController {
    @Autowired
    private ICountService iCountService;

    /**
     * 客户统计
     * @param year
     * @return
     */
   @RequestMapping("/count/associator")
   public List<AssocitatorDto> associator(Integer year){
       String preYear = year.toString();
       Integer year2 = year+1;
       String lastYear = year2.toString();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
       Date time1 = null;
       long startTime = 0;
       if (preYear != "" && preYear != null) {
           try {
               time1 = sdf.parse(preYear);
               startTime = time1.getTime();
           } catch (ParseException e) {
               e.printStackTrace();
           }
       }
       Date time2 = null;
       long endTime = 0;
       if (lastYear != "" && lastYear != null) {
           try {
               time2 = sdf.parse(lastYear);
               endTime = time2.getTime();
           } catch (ParseException e) {
               e.printStackTrace();
           }
       }


       return iCountService.associatorCount(startTime,endTime);
   }

    /**
     * 活动统计
     * @param year
     * @return
     */
   @RequestMapping("/count/activity")
   public List<ActivityDto> activity(Integer year){
       String preYear = year.toString();
       Integer year2 = year+1;
       String lastYear = year2.toString();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
       Date time1 = null;
       long startTime = 0;
       if (preYear != "" && preYear != null) {
           try {
               time1 = sdf.parse(preYear);
               startTime = time1.getTime();
           } catch (ParseException e) {
               e.printStackTrace();
           }
       }
       Date time2 = null;
       long endTime = 0;
       if (lastYear != "" && lastYear != null) {
           try {
               time2 = sdf.parse(lastYear);
               endTime = time2.getTime();
           } catch (ParseException e) {
               e.printStackTrace();
           }
       }
       return iCountService.activityCount(startTime,endTime);
   }
   /**
    *
    * 功能描述: 资金统计
    *
    * @param:
    * @return:
    * @auther: yaozun
    * @date:
    */
   @RequestMapping("/count/finance")
   public List<FinanceDto> finance(Integer year){
       String preYear = year.toString();
       Integer year2 = year+1;
       String lastYear = year2.toString();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
       Date time1 = null;
       long startTime = 0;
       if (preYear != "" && preYear != null) {
           try {
               time1 = sdf.parse(preYear);
               startTime = time1.getTime();
           } catch (ParseException e) {
               e.printStackTrace();
           }
       }
       Date time2 = null;
       long endTime = 0;
       if (lastYear != "" && lastYear != null) {
           try {
               time2 = sdf.parse(lastYear);
               endTime = time2.getTime();
           } catch (ParseException e) {
               e.printStackTrace();
           }
       }
       return iCountService.financeCount(startTime,endTime);
   }
}
